package com.design.cjm.behavioral.command.example1;

/**
 * 通过它来调用命令
 *
 * @Author: Jie Ming Chen
 * @Date: 2018/9/28
 * @Version 1.0
 */
public class Invoker {

    private Command[] onCommands;

    private Command[] offCommands;

    private final int slotNum = 7;

    public Invoker() {

        this.onCommands = new Command[slotNum];
        this.offCommands = new Command[slotNum];
    }

    public void setOnCommand(Command onCommand, int slot) {
        this.onCommands[slot] = onCommand;
    }

    public void setOffCommand(Command offCommand, int slot) {
        this.offCommands[slot] = offCommand;
    }

    public void onButtonWasPushed(int slot) {
        onCommands[slot].execute();
    }

    public void offButtonWasPushed(int slot) {
        offCommands[slot].execute();
    }
}
